package com.zoujt.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

/*
 * @auth zoujt
 * @date 2021/2/26
 * @Description
 */

public class BaseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String uri = req.getRequestURI();
        String[] split = uri.split("/");
        String methodName = split[split.length - 1];

        try {
            Class clazz = this.getClass();
            Method declaredMethod = clazz.getDeclaredMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
            declaredMethod.setAccessible(true);
            declaredMethod.invoke(this,req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }

//        if (uri.endsWith("list")){
//            list(req,resp);
//        }else if (uri.endsWith("add")){
//            add(req,resp);
//        }

    }
}
